#!/usr/bin/perl 
use DBI;
use CGI;
use TTraker;

& print_header;
& initialize_dbi;

my $form_ref = &parse_input;
my %FORM_DATA = %$form_ref; 
my $num = $FORM_DATA{'empNum'};
my $name = $FORM_DATA{'empName'};
my $job = $FORM_DATA{'empJob'};
my $loc = $FORM_DATA{'empLoc'};
my $cli = $FORM_DATA{'cliID'};
my $task = $FORM_DATA{'taskID'};
my $desc = $FORM_DATA{'description'};
my $units = $FORM_DATA{'units'};
my $stdMin= $FORM_DATA{'stdMin'};
my $stdRate= $FORM_DATA{'stdRate'};
my $whs= $FORM_DATA{'show_whs'};
my $csr= $FORM_DATA{'show_csr'};
my $admin= $FORM_DATA{'show_adm'};
my $in =  $FORM_DATA{'inbound'};
my $out =  $FORM_DATA{'outbound'};
my $msg = ""; 
my $errlev = 0;

if ($cli eq "" || $task eq "" || $desc eq "" || $units eq "" || $stdMin eq "" || $stdRate eq "") {
	$msg = "Description, Units, Standard Minutes, Contract Rate and Show must all have values!<br/>";
	$errlev ++; 
}
if ( $csr eq "" && $whs eq "" && $admin eq "" ) {
	$msg = "$msg" . "Must show task to at least one of WHS, CSR and ADMIN!<br/>";
	$errlev ++; 
}	
if ( $in eq "" && $out eq "") {
	$msg = "$msg" . "Task must be Inbound, Outbound or both!<br/>";
	$errlev ++; 
}	
if ($errlev == 0) {
	adm_add_new_client_task ($cli, $task, $desc, $units, $stdMin, $stdRate, $whs, $csr, $admin, $in, $out);
	$msg = "Task $task added for client $cli";  
	adm_activity_screen_from_pm ($num, $name, $job, $loc, $msg);
} else {
	if ( $whs eq "on" ) { push @checked, "CHECKED"; } else { push @checked, ""; }
	if ( $csr eq "on" ) { push @checked, "CHECKED";	} else { push @checked, ""; }
	if ( $admin eq "on" ) { push @checked, "CHECKED"; } else { push @checked, ""; }
	if ( $in eq "on" ) { push @checked, "CHECKED"; } else { push @checked, ""; }
	if ( $out eq "on" ) { push @checked, "CHECKED"; } else { push @checked, ""; }
	my $chkd = \@checked;
	& refresh_adm_add_task_detailed_screen_message ($num, $name, $job, $loc,$cli, $task, $desc, $units, $stdMin, $stdRate, $whs, $csr, $admin, $in, $out, $msg, $chkd);
}	

db_disconnect();

##################### SUBROUTINES FOLLOW  #####################


sub refresh_adm_add_task_detailed_screen_message
{
my $num = $_[0];
my $name = $_[1];
my $job = $_[2];
my $empLoc = $_[3];
my $cli = $_[4];
my $task = $_[5];
my $desc = $_[6];
my $units = $_[7];
my $stdMin = $_[8];
my $stdRate = $_[9];
my $whs = $_[10];
my $csr = $_[11];
my $admin = $_[12];
my $in = $_[13];
my $out = $_[14];
my $msg = $_[15];
my $chkd = $_[16];
my @checked = @$chkd;

print <<ENDHEADER;
<html>
<head>
<link rel='stylesheet' type='text/css' href='${css_ref}trak.css' />
<script type='text/javascript' src='${js_ref}trak.js'></script>
<title>trak_03 adm_client_task_detail_screen</title>
</head>
<body>
<h2><center>${banner}</center></h2>
<hr/>
<div id='box5_1'>
<h3>New Task: $task &nbsp&nbsp&nbsp&nbsp Client: $cli</h3>
<form autocomplete='off' name='startJob' action='${cgi_ref}trak_04_adm_add_client_task.pl' method='post'>
<div id='box5_2'>
<input type="hidden" name=empNum value='$num'/>
<input type="hidden" name=empName value='$name'/>
<input type="hidden" name=empJob value='$job'/>
<input type="hidden" name=empLoc value='$loc'/>
<input type="hidden" name=cliID value='$cli'/>
<input type="hidden" name=taskID value='$task'/>
<table>
	<tr>
		<td>Description:</td>
		<td><input type="text" name=description size="48" value=$desc></td>
	</tr>
	<tr>
		<td>Units:</td>
		<td><input type="text" name=units size="8" value=$units></td>
	</tr>
	<tr>
		<td>Standard Min:</td>
		<td><input type="text" name=stdMin size="8" value=$stdMin ></td>
	</tr>
	<tr>
		<td>Contract Rate:&nbsp&nbsp</td>
		<td><input type="text" name=stdRate size="8" value=$stdRate></td>
	</tr>
</table>
<br/><br/>Show on the following lists:
<br/><br/>
<label><input type=checkbox name=show_whs $checked[0]>&nbsp&nbsp&nbsp WHS</label>
<label><input type=checkbox name=show_csr $checked[1]>&nbsp&nbsp&nbsp CSR</label>
<label><input type=checkbox name=show_adm $checked[2]>&nbsp&nbsp&nbsp ADMIN</label>
<br/><br/>
<label><input type=checkbox name=inbound $checked[3]>&nbsp&nbsp&nbsp Inbound</label>
<label><input type=checkbox name=outbound $checked[4]>&nbsp&nbsp&nbsp Outbound</label>
<br/><br/>
<input type='submit' name='submit' value='Proceed'>
<br/><br/>
<a href="${cgi_ref}trak_00_adm_activity.pl?num=$num&name=$name&job=$job&loc=$loc">Return to Activities</a>
<br/><br/>
<b id="warn">$msg</b>
</div>
</form>
</body>
</html>

ENDHEADER

}



